package org.bringer.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.AccessType;


@Entity
@Table(name = "account")
@AccessType("field")
@XmlRootElement
public class Account extends BaseObject implements Serializable {
    

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)    
	private Long id;
	@Column(nullable = false, length = 100)   
    private String description;
    @Column(nullable = false, length = 34, unique = true)
    private String ibanCode; 
    @Column(nullable = true)
    private Integer version;
    @Column(nullable = false)
    private Double balance;
    
    @OneToMany(fetch = FetchType.EAGER,mappedBy="account")
    @XmlTransient
    private Set<Annotation> annotations = new HashSet<Annotation>();
    @ManyToOne   
    @JoinColumn(name="owner_id")
    @XmlTransient
    private User owner;
    @OneToOne
    @PrimaryKeyJoinColumn(name="account_id")
    private AccountBalance currentBalance;
    public AccountBalance getCurrentBalance() {
		return currentBalance;
	}




	public void setCurrentBalance(AccountBalance currentBalance) {
		this.currentBalance = currentBalance;
	}




	public Account() {
    }

    

   
    public Long getId() {
        return id;
    }

  
    
    public String getIbanCode() {
        return ibanCode;
    }

    @Column(nullable = false)   
   
    public Double getBalance() {
        return balance;
    }


    @Version
    public Integer getVersion() {
        return version;
    }

    public String toString() {
        ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
                .append("ibanCode", this.ibanCode)
                .append("balance", this.balance);

     
        return sb.toString();
    }



	@Override
	public boolean equals(Object o) {
		// TODO Auto-generated method stub
		return false;
	}



	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		 return (ibanCode != null ? ibanCode.hashCode() : 0);
	}
	
	@XmlTransient
	 public Set<Annotation> getAnnotations() {
	     return annotations;
	 }


	 @XmlTransient
	public User getOwner() {
		return owner;
	}



	public void setOwner(User owner) {
		this.owner = owner;
	}



	public void setId(Long id) {
		this.id = id;
	}



	public void setIbanCode(String ibanCode) {
		this.ibanCode = ibanCode;
	}



	public void setVersion(Integer version) {
		this.version = version;
	}



	public void setBalance(Double balance) {
		this.balance = balance;
	}



	public void setAnnotations(Set<Annotation> annotations) {
		this.annotations = annotations;
	}


	
	public String getDescription() {
		return description;
	}



	public void setDescription(String description) {
		this.description = description;
	}

	
	 
}
